<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="email=no" name="format-detection" />
		<title>主动定位</title>
		<!--<link rel="stylesheet" href="../../css/mui.min.css" />-->

		<link rel="stylesheet" href="../../css/s_plus.css" />
		<link rel="stylesheet" href="../../css/base.css" />
		<link rel="stylesheet" href="../../css/layout.css" />
		<link rel="stylesheet" href="../../css/choice.css" />
		<link rel="stylesheet" href="../../css/hui.css" />

		<script type="text/javascript" src="../../libs/vue.js"></script>
		<script type="text/javascript" src="../../js/jquery.1.9.1.min.js"></script>
		<script type="text/javascript" src="../../js/app/url.js"></script>
		<script type="text/javascript" src="../../libs/hui.js" ></script>
		<script type="text/javascript" src="../../js/app/api.js"></script>
		<script type="text/javascript" src="../../js/control/pop.js"></script>
		<script type="text/javascript" src="../../js/md5.js"></script>
		<script type="text/javascript" src="../../js/mui.min.js"></script>

		<!--<script type="text/javascript" src="../work/menu.js"></script>-->
		<script type="text/javascript" src="../../js/control/swal/sweetalert.min.js"></script>
		<link rel="stylesheet" href="../../js/control/swal/sweetalert.css" />

		<!-- 在页面的头部应用点聚合工具开源库的文件 -->
		<!--<script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js"></script>-->

		<!--<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=a82yNQICnHARgGpKuPH1wWZWQcBD2Llo"></script>-->

		<style>
			/*隐藏百度地图 底部LOGO*/
			
			.BMap_cpyCtrl {
				display: none;
			}
			
			.anchorBL {
				display: none;
			}
		</style>

	</head>

	<body>
		<section id="wrapper" class="wrapper">
			<section class="pusher">
				<section class="sidenav sidebtn">
					<!--侧边栏-->

				</section>

				<header class="f_l maxbox subhead">
					<a class="side_arrow f_l arrow_l" data-effect="sidebtn"><i class="iconfont">&#xe600;</i></a>
					<h1>主动定位</h1>
				</header>
				<!--<section class="f_l maxbox edit_list">
  <ul>
    <li>
      <a class="edit_a">
        <b>当前位置</b>{{address}}
      </a>
    </li>
  </ul>
</section>-->
				<section class="f_l maxbox mar_f">
					<div id="allmap" style="text-align: center; width: 100%;"></div>
				</section>
				<section class="f_l maxbox mar_t mar_f t_c">
					<a class="btn mian_btn" id="tj">提交</a>
				</section>
			</section>
		</section>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=sGSOaO07WkRHHiCRxxbSQVBn"></script>

		<script>
			//动态插入公用菜单JS
			var menuJsPath = "../work/menu.js?time=";
			var randomh = Math.random();
			var e = document.getElementsByTagName("script")[0];
			var d = document.createElement("script");
			d.src = menuJsPath + randomh + "";
			d.type = "text/javascript";
			d.async = true;
			d.defer = true;
			e.parentNode.insertBefore(d, e);

			var head = $(".subhead").height();
			var foot = $(".edit_list").height();
			var foot2 = +$(".t_c").height();
			var pageHeight = $(document).height();
			var mapHeight = pageHeight - (head + foot + foot2);

			$("#allmap").height(mapHeight - 50);

			var sp = new Vue({
				el: "#wrapper",
				data: {
					address: "",
					params: {
						longitude: "",
						latitude: "",
						"userId.id": ""
					}

				}

			});

			mui.plusReady(function() {
				//      getInfo();
				map = new BMap.Map("allmap");
				var point = new BMap.Point(116.331398, 39.897445);
				map.centerAndZoom(point, 18);
				getGeocode();
			})

			// 通过定位模块获取位置信息
			function getGeocode() {
//				 plus.nativeUI.showWaiting();
				hui.loading("定位中");
				plus.geolocation.getCurrentPosition(showLocation, function(e) {
//					mui.toast("获取定位位置信息失败：" + e.message);
					hui.toast("获取定位位置信息失败：" + e.message);
				}, {
					geocode: true
				});
			}

			//处理定位后的信息
			function showLocation(r) {
				jingDu = r.coords.longitude;
				weiDu = r.coords.latitude;
				Address = r.addresses;
				centerPointer = new BMap.Point(r.coords.longitude, r.coords.latitude);
				exchange();
			}

			//将GPS坐标转换成百度地图的坐标
			function exchange() {
				var convertor = new BMap.Convertor();
				var pointArr = [];
				pointArr.push(centerPointer);
				convertor.translate(pointArr, 1, 5, translateCallback);
			}

			function translateCallback(data) {
				if(data.status == 0) {
					var myIcon = new BMap.Icon("../../images/danger02.png", new BMap.Size(30, 30));
					//					var mk = new BMap.Marker(r.point,{icon:myIcon});
//					alert(JSON.stringify(data.points[0]));
					var marker = new BMap.Marker(data.points[0], {
						icon: myIcon
					});
					map.addOverlay(marker);
					map.setCenter(data.points[0]);
					
					var paramPoint= data.points[0];
					sp.params.longitude=String(paramPoint.lng);
				sp.params.latitude=String(paramPoint.lat);
					hui.closeLoading();
//					plus.nativeUI.closeWaiting();
				}
			}

			//		// 百度地图API功能
			//			var map = new BMap.Map("allmap");
			//			var point = new BMap.Point(112.9453203518,28.2340227593);
			//			map.centerAndZoom(point, 16);
			////			map.enableScrollWheelZoom(false);
			//			 map.enableDragging(); 
			//			var geolocation = new BMap.Geolocation();
			//			geolocation.enableSDKLocation();
			//
			//			geolocation.getCurrentPosition(function(r) {
			//				if(this.getStatus() == BMAP_STATUS_SUCCESS) {
			//					
			//				var myIcon = new BMap.Icon("../../images/danger02.png", new BMap.Size(300,157));
			//					var mk = new BMap.Marker(r.point,{icon:myIcon});
			////					mk.addEventListener("click",attribute);
			//		var p = mk.getPosition();		
			//         console.log("marker的位置是" + p.lng + "," + p.lat);
			//
			//					
			//					var point = new BMap.Point(r.point.lng, r.point.lat); //用所定位的经纬度查找所在地省市街道等信息
			//					sp.params.longitude=String(r.point.lng);
			//					sp.params.latitude=String(r.point.lat);
			//					exchange(point);
			//					
			////					map.addMarker(mk);
			//						map.addOverlay(mk); //标出所在地
			//
			//			
			//				map.panTo(point); 
			//					
			//					var gc = new BMap.Geocoder();
			//					gc.getLocation(point, function(rs) {
			//						var addComp = rs.addressComponents;
			//						console.log(rs.address); //地址信息
			//						sp.address=rs.address;
			//						//alert(rs.address);//弹出所在地址
			//					});
			//				} else {
			//					alert('定位失败，请检查您的手机定位功能是否打开' + this.getStatus());
			//				}
			//			}, {
			//				enableHighAccuracy: true
			//			})

			$("#tj").click(function() {
				save();
			});

			function save() {

				var path = urlManager.saveUserTrajectory();
				console.log(path);
				var username = localStorage.getItem("username");
				var sec = localStorage.getItem("sec_pwd");
				var time = apiManage.getNow();
				var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
				//	   	console.log(key);
				var paramKey = hex_md5(key);

				var userid = localStorage.getItem("userid");
				sp.params["userId.id"] = userid;

				console.log("path============================" + path);
				console.log("params===================" + JSON.stringify(sp.params));
				hui.loading("数据上传中..");
				$.ajax({
					type: "POST",
					url: path,
					data: sp.params,
					beforeSend: function(request) {
						request.setRequestHeader("loginName", username);
						request.setRequestHeader("time", time);
						request.setRequestHeader("sign", paramKey);
					},
					success: function(result) {
						console.log("主动上传============================" + JSON.stringify(result));
						hui.closeLoading();

						swal({  
								title: "主动定位成功",
								  text: "",
								  type: "success",
								  showCancelButton: false,
								  confirmButtonColor: "#DD6B55",
								  confirmButtonText: "确认",
								  cancelButtonText: "取消",
								  closeOnConfirm: true,
								  closeOnCancel: false
							},
							function(isConfirm) {  
								if(isConfirm) {
									//				 		hui.open("terminal.html", {}, true, {});  
								} else {  }
							});

					}
				});

			}
		</script>
	</body>

</html>

<!--侧边栏向左移动效果*该放在head无效-->
<script src="../../js/modernizr.custom.js"></script>
<script src="../../js/classie.js"></script>
<script src="../../js/sidebarEffects.js"></script>